<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
file:///F:/PDC/ProjectEnv/workspace/Yule8xDocument/八星代理管理系统/toolkit/权限规则生成器.html
-->
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>权限规则生成器</title>
<!-- Tell the browser to be responsive to screen width -->
<meta
	content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
	name="viewport" />
<style type="text/css">
body {
	font-size: 12px;
}
</style>
</head>
<body>
	<div id="examplecode" style="display:none">[{
    "title": "代理",
    "children": [{
        "title": "居间商管理",
        "url":"/middleman",
    }, {
        "title": "代理管理",
        "url":"/agency",
    }, {
        "title": "用户管理",
        "url":"/member",
    }, ]
}, {
    "title": "管理员",
    "children": [{
        "title": "管理员管理",
        "url":"/admin",
    }, {
        "title": "角色管理",
        "url":"/authrole",
    }, ]
}, {
    "title": "财务",
    "children": [{
        "title": "提现管理",
        "url":"/withdraw",
    }, {
        "title": "充值管理",
        "url":"/recharge",
    }, {
        "title": "资金交易明细",
        "url":"/transactiondetail",
    }, {
        "title": "钻石交易明细",
        "url":"/diamondtransactiondetail",
    }, ]
}, ]
	</div>
	<form id="form1" onsubmit="return false;">
		<div>
			规则内容（必需包含title和children属性名称）：<a href="#" onclick="return showExample()">查看示例</a><br />
			<textarea id="rules" cols="120" rows="15"></textarea>
			<br />
			<button onclick="return generate()">立即生成</button>
		</div>
	</form>
	<textarea id="result" cols="120" rows="30"></textarea>
	<script type="text/javascript">
	function showExample(){
		$id("rules").value=$id("examplecode").innerText;
		return false;
	}
		// 2017-5-13
		function generate() {
			var rules = $id("rules").value;
			var strout=generate_sql(rules);
			$id("result").value = strout;
			return false;
		}

		/**
		 * 生成SQL语句
		 */
		function generate_sql(rules) {
			if(!rules){
				return "";
			}
			var strout = "", ln = "\r\n";
			var children2, n=0,n1=0;
			var arules = new Function("return "+rules)();
			for ( var i1 in arules) {
				n++;
				strout+="INSERT INTO dbo.t_auth_rule (id, title) VALUES ("+n+", '"+arules[i1]["title"]+"');"+ln;
				n1=n;
				children2=arules[i1]["children"];
				for(var i2 in children2){
					n++;
					strout+="INSERT INTO dbo.t_auth_rule (id, title, pid, parent1_id, url) VALUES ("+n+", '"+children2[i2]["title"]+"', "+n1+", "+n1+", '"+children2[i2]["url"]+"');"+ln;
				}
				strout+="-- /"+arules[i1]["title"]+ln;
			}
			strout="SET IDENTITY_INSERT t_auth_rule ON"+ln+strout+"SET IDENTITY_INSERT t_auth_rule OFF";
			return strout;
		}
		function $id(id) {
			return document.getElementById(id);
		}
	</script>
</body>
</html>